import { Component, Vue } from "vue-property-decorator";
import { getToken } from "./auth";

@Component
export default class UploadParameter extends Vue {
  get uploadHeaders(): any {
    return {
      Accept: "application/json, text/plain, */*",
      authorization: "Bearer " + getToken(),
    };
  }

  // 上传的图片服务器地址
  get uploadImgUrl(): string {
    return process.env.VUE_APP_BASE_API + "/common/upload";
  }

  // 图片上传前
  uploadBefore(file: File): boolean {
    const fileType = file.type;
    if (
      fileType === "image/jpeg" ||
      fileType === "image/png" ||
      fileType === "image/gif"
    ) {
      return true;
    } else {
      this.$message.error("请插入图片类型文件(jpg/jpeg/png/gif)");
      return false;
    }
  }

  uploadError(): void {
    // loading动画消失
    this.$message.error("图片插入失败");
  }
}
